
<?php 
/* 
Template Name: prosessing_admin_delngdung-ajax
*/
?>
<?php
if ( !is_user_logged_in() ) 
    {
      ?>

        <div id='content_nano_two' class='clearfix' style='min-height:300px;'>
              <h1 style='color:#000;'>bạn không được phép truy cập trang này </h1>
              <?php wp_die( __( 'Vui lòng đăng nhập hoặc quay lai trang chủ ! ' ) ); ?>
        </div>
         
     <?php 
          
    }//if ( ! current_user_can( 'list_users' ) ) 
    elseif (is_user_logged_in() )  
 { 

    if ( ( $current_user->roles[0] == 'author') or ( $current_user->roles[0] == 'contributor') or ( $current_user->roles[0] == 'subscriber') ) 
      {
       ?>

        <div id='content_nano_two' class='clearfix' style='min-height:300px;'>
              <h1 style='color:#000;'>bạn không được phép truy cập trang này </h1>
              <?php wp_die( __( 'Vui lòng đăng nhập hoặc quay lai trang chủ ! ' ) ); ?>
        </div>
         
     <?php 

      }//if ( ( $current_user->roles[0] == 'author') or ( $current_user->roles[0] == 'contributor') or ( $current_user->roles[0] == 'subscriber') ) 
      elseif ( ( $current_user->roles[0] != 'author') or ( $current_user->roles[0] != 'contributor') or ( $current_user->roles[0] != 'subscriber') )
      {
                        $id_may = $_POST['idmay'];
                        $ID = $_POST['nguoidung'];
                        $wpdb->delete( 'wp_user_wp_may', array( 'ID' => $ID ), array( '%d' ) );

                          $sql = "SELECT wp_user_wp_may.ID,wp_user_wp_may.id_may,wp_users.ID,wp_users.user_login
                            FROM wp_user_wp_may
                            INNER JOIN wp_users
                            ON wp_users.ID = wp_user_wp_may.ID
                            WHERE wp_user_wp_may.id_may = ".$id_may ;
                                                //echo $sql ;
                                                 $row = $wpdb->get_results($sql);
                                                 //var_dump($row );
                                                ?> 
                                               <table class="wp-list-table widefat fixed users" cellspacing="0">
                                                    <thead>
                                                     <tr>
                                                       <th scope="col" id="cb"  style=""> </th>
                                                       <th scope="col" id="username"  style=""> <span>Tài khoản</span></th>
                                                       <th scope="col" id="name"  style=""><span>Tên người dùng</span></th>
                                                       <th scope="col" id="email"style=""></th>
                                                     </tr>
                                                    </thead>
                                                     <tbody id="the-list" data-wp-lists="list:user">
                                        <?php 
                                          foreach($row as $key=>$value)
                                         {
                                          //var_dump($value);//break;
                  // truy van lay quyen quan tri
                   $id_user_meta_data = $wpdb->get_results("SELECT * FROM wp_usermeta WHERE user_id = ".$value->ID);

                     foreach ($id_user_meta_data as $key =>$vlue) 
                         {
                                                       
                           if  ( ( $vlue ->meta_value == 'a:1:{s:11:"contributor";b:1;}' )  or  ($vlue ->meta_value == 'a:1:{s:6:"editor";b:1;}' ) )
                             {
                                         ?>
                                              <tr id="user-<?php echo $value->ID; ?>" class="alternate">
                                                   <th scope="row" class="check-column">
                                                     <label class="screen-reader-text" for="cb-select-1"></label>
                                                   </th>
                                                     <td class="username column-username">
                                                       <strong><?php echo $value->user_login;?></strong>
                                                    </td>
                                                    <td class="name column-name"><?php echo $value->display_name;?></td>
                                                    <td class="email column-email">
                                                       
                                                       <ul style='position: relative;'>
                                                        <li style='height: 30px;'>
                                                        <input type="button" 
                                                         nguoidung="<?php echo $value->ID; ?>" 
                                                         idmay="<?php echo $id_may;?>"
                                                         name="delng<?php echo $value->ID; ?>" 
                                                         id="delnguoidung" 
                                                         class="delnguoidung"
                                                         value="Xóa"
                                                         />
                                                       </li></ul>
                                                         
                                                    </td>
                                                                                         
                                                      </tr><!-- id="user-xyz" class="alternate" -->
  
                                       <?php             
            }// if ($vlue ->meta_value == 'a:1:{s:11:"contributor";b:1;}') 
          }//   foreach ($id_user_meta_data as $key =>$vlue) 
           
    }// foreach($row as $key=>$value)
                                          ?>

                                   </tbody>
                             </table>
                              <script type="text/javascript">
                               jQuery(document).ready(function(){
                                    $("td input[name^='delng']").click(function() {
                                    var nguoidung = $(this).attr("nguoidung");
                                    var idmay = $(this).attr("idmay");
                                    $.ajax({
                                            url:"<?php bloginfo('url');?>/prosessing_admin_delngdung",
                                              type:"POST",
                                              data: {nguoidung:nguoidung,idmay:idmay},
                                              success: function(data)
                                              {
                                               // alert(data);
                                                $('#phanquyennguoidungadmin').html(data);
                                               }
                                        });
                                    });
                                      
                                  })
                             
                 </script>
                      <?php 
                        echo '<h1></h1>';
                        echo '<h1>Xóa 1 người dùng thành công</h1>';
                       // var_dump($ID);
                       //var_dump($xoa_may_userID);
                        return;
 
                        
 } //  elseif ( ( $current_user->roles[0] != 'author') or ( $current_user->roles[0] != 'contributor') or ( $current_user->roles[0] != 'subscriber') )
} //elseif ( ! current_user_can( 'list_users' ) ) ?>
